package com.codestudy.controller;

import com.codestudy.entity.RequestData;
import com.codestudy.entity.Result1;
import com.codestudy.service.impl.AIQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/qwen-plus")
@Slf4j
@CrossOrigin
@Api(tags = "Qwen_Plus相关接口")
public class QwenPlusController {

    @Autowired
    private AIQuestionService aiQuestionService;

    @PostMapping("/ask")
    @ApiOperation(value = "流式调用", notes = "要调用websocket格式的数据要用/ws-ask，通过WebSocketConfig转发")
    public Result1 askAI(@RequestBody RequestData requestData) {
        try {
            String answer = aiQuestionService.askAI(requestData.getQuestion(), requestData.getUserId());
            return Result1.success(answer);
        } catch (Exception e) {
            log.error("An exception occurred: {}", e.getMessage(), e);
            return Result1.error(e.getMessage());
        }
    }
}